package com.wits.platform.common.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	/** yyyy-MM-dd HH:mm **/
	public static final String PATTERN="yyyy-MM-dd HH:mm";
	
	/** yyyy-MM-dd**/
	public static final String PATTERN_SIMPLE="yyyy-MM-dd";
	
	/** yyyy-MM-dd HH:mm:ss **/
	public static final String PATTERN_FULL="yyyy-MM-dd HH:mm:ss";
	
	
	
	/**
	 * 在当前时间之前 return true
	 * @param date
	 * @return
	 */
	public static boolean nowBefore(Date date) {
		if (date == null) {
			return false;
		}
		return new Date().after(date);
		
	}
	
	/**
	 * 在当前时间之后 返回 true
	 * @param date
	 * @return
	 */
	public static boolean nowAfter(Date date) {
		if (date == null) {
			return false;
		}
		return new Date().before(date);
		
	}
	
	
	public static String format(Date date){
		if(date==null){
			return "";
		}
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return df.format(date);
	}
	
	public static String format(Date date,String pattern){
		if(date==null){
			return "";
		}
		DateFormat df=new SimpleDateFormat(pattern);
		return df.format(date);
	}

	
	public static String currentTime(){
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return df.format(new Date());
	}
	
	public static Date getNow(){
		return new Date();
	}
	
	public static String long2Str(long time,String pattern){
		DateFormat formater=new java.text.SimpleDateFormat(pattern);
		return formater.format(new Date(time));
		
	}
	
	
	/**
	 * 
	 * @return yyyy-MM-dd
	 */
	public static String getDateString(){
		DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
		return df.format(new Date());
	}
	
	/**
	 * 
	 * @return HH:mm:ss
	 */
	public static String getTimeString(){
		DateFormat df=new SimpleDateFormat("HH:mm:ss");
		return df.format(new Date());
	}
	
	/**
	 * 
	 * @return HH:mm
	 */
	public static String getHHMM(){
		DateFormat df=new SimpleDateFormat("HH:mm");
		return df.format(new Date());
	}
	
	
	public static Date parse(String source,String pattern){
		Date date=null;
		DateFormat df=new SimpleDateFormat(pattern);
		try {
			date=df.parse(source);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}

}
